package com.example.javaairportflightanalysis.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.javaairportflightanalysis.common.ApiRestResponse;
import com.example.javaairportflightanalysis.domin.userpojo.Permission;
import com.example.javaairportflightanalysis.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    @GetMapping("/findAllPermission")
    @SaCheckRole("ROLE_ADMIN")
    public ApiRestResponse findAllPermission(){
        return ApiRestResponse.success(permissionService.findAllPermission());
    }
    @PostMapping("/addPermission")
    @SaCheckRole("ROLE_ADMIN")
    public ApiRestResponse addPermission(@RequestBody Permission permission){
        permissionService.addPermission(permission);
        return ApiRestResponse.success();
    }
    @GetMapping("/deletePermission")
    @SaCheckRole("ROLE_ADMIN")
    public ApiRestResponse deletePermission(@RequestParam Integer id){
        permissionService.deletePermission(id);
        return ApiRestResponse.success();
    }
    @PostMapping("/updatePermission")
    @SaCheckRole("ROLE_ADMIN")
    public ApiRestResponse updatePermission(@RequestBody Permission permission){
        permissionService.updatePermission(permission);
        return ApiRestResponse.success();
    }
}
